<div class="easyui-panel" style="padding:10px;" data-options="fit:true,border:false">
    <div class="easyui-layout" data-options="fit:true">
    	<div data-options="region:'south'" style="text-align:right; height:40px; border-width:1px 0 0 0; padding-top:5px;overflow:hidden">
            <a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="select_files_in()" style="width:80px">确定</a>
            <a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" href="javascript:void(0)" onclick="javascript:$('#dialog_custom_box').dialog('close')" style="width:80px">取消</a>  
        </div>
        <div data-options="region:'west',split:true" style="width:220px; padding:10px;">
        	<div id="select_file_cabinets_root" style="height:18px;cursor:pointer;" onclick="select_root_directory_t()"><span class="tree-icon tree-folder icon-folder" style="margin-top:-2px"></span> 个人文件柜</div>
        	<ul id="select_folder_list"></ul>
        </div>
        <div data-options="region:'center'">
            <div><table id="select_file_list_dg"></table></div>
        </div>
    </div>
</div>
<script>
var select_folder_str = '';
//渲染目录树
function select_file_folder_tree(){
	$('#select_folder_list').tree({
		url:'<?php echo base_url('file_cabinets/folder_list?_=')?>'+GetRandomNum(),
		animate:true,
		lines:false,
		fit:true,
	});
}
select_file_folder_tree();

//选择个人文件柜字符串的动作函数
function select_root_directory_t(){
	select_file_folder_tree();//刷新树，可以清除选中状态
	select_root_directory();//刷新列表，回到更目录并显示根目录的文件列表
	$("#select_file_cabinets_root").addClass("tree-node tree-node-selected");//在个人文件柜字符上添加选中样式
}

//文件列表函数默认显示根目录的文件列表
function select_root_directory(select_folder_str){
	var url = (select_folder_str)?'/'+encodeURI(select_folder_str):'';
	$('#select_file_list_dg').datagrid({		
		url:'<?php echo base_url('file_cabinets/files_list')?>'+url,
		singleSelect:true,
		border:false,
		fitColumns:true,
		columns:[[
			{field:'id',hidden:true},
			{field:'filename',title:'名称',width:280},
			{field:'filesize',title:'大小',width:60,align:'right'}
		]]
	});
}
select_root_directory();

//文件目录树的点击事件
$('#select_folder_list').tree({	
	onSelect : function(node) {
		$("#select_file_cabinets_root").removeClass("tree-node tree-node-selected");
		select_folder_str = '';//每选中一次都清空上一次点击后生成的数据		
		//返回树对象
		var tree = $(this).tree;
		//选中的节点是否为叶子节点,如果不是叶子节点,清除选中
		var isLeaf = tree('isLeaf', node.target);
		if (!isLeaf) {
			//不是叶子节点时展开该节点
			$('#select_folder_list').tree('toggle',node.target);
		}else{		
			//alert(node.text);
		}
		
		
		do{
			select_folder_str = node.text+'/'+select_folder_str;
			var node=$('#select_folder_list').tree('getParent',node.target);
		}while(node);
		select_root_directory(select_folder_str);
	}
});
	
//获取选中的文件，并返回数组
function select_files_select(){
	var getobj = $('#select_file_list_dg').datagrid("getChecked");
	var getname = [];
		$.each(getobj, function(index, item){
			getname.push(item.filename);
		}); 
	return getname;
}


//存入文件到文件柜
function select_files_in(){
	var m = '<?php echo $m;?>';
	var id = '<?php echo $id;?>';
	var filename = '<?php echo $filename;?>';
	$.post("<?php echo base_url('file_cabinets/select_files_in');?>",{
		getpath:select_folder_str,
		m:m,
		id:id,
		filename:filename
	},function(data){
		if(data.success){
			$('#dialog_custom_box').dialog('close');
		}else{
			$.messager.alert('提示',errorMsg,'warning');	
		}
	},'JSON');
	
}
</script>